/*
 This file 'scroll' is part of Firebird Integrated Solution 1.0

 Copyright (c) 2020 Lincong

 Contact:  
        Email: lincong1987@gmail.com

        QQ: 159257119
 
 See Usage at http://www.jplatformx.com/firebird

 Create date: 2020-06-03 16:39
 */

define(function (require, exports, module) {

	var $ = require("jquery");

	/**
	 * 
	 * @param options
	 */
	$.fn.goodScroll = function (options) {
		var defaults = {speed: 40, content: "li"};
		var opts = $.extend({}, defaults, options), intId = [];

		function marquee($this, height, opts) {

			$this.animate({scrollTop: '+=1'}, 0, function () {
				var scrollTop = Math.abs(parseInt($this.scrollTop(), 10));
				if (scrollTop + $this.height() >= height) {
					$this.animate({scrollTop: 0}, 300);
				}
			});
		}

		this.each(function (i) {
			var $this = $(this),
				height = $this.find(opts.content).height(),
				speed = opts.speed;

			intId[i] = setInterval(function () {
				marquee($this, height, opts);
			}, speed);

			 
			$this.hover(
				function () {
					clearInterval(intId[i]);
				},
				function () {
					intId[i] = setInterval(function () {
						marquee($this, height, opts);
					}, speed);
				}
			);


		});
	}

});